Direct memory access (DMA) allows hardware devices in a computer to access system memory for reading and/or writing independently of the central processing unit (CPU). Hardware devices that are capable of performing DMA include disk drive controllers, graphics cards, network cards and sound cards. While a hardware device is performing the DMA, the CPU can engage in other operations. DMA is especially useful in real-time computing applications where it is critical to avoid the stalling of concurrent operations.
A computer having DMA-capable devices often uses an input/output memory management unit (IOMMU) to manage address translations. An IOMMU is a hardware memory management unit (MMU) that resides on the input/output (I/O) path connecting the device to the memory. The IOMMU maps the device address space (e.g., a bus address) that is relevant to the I/O bus into the physical address space (e.g., a host physical address) that is relevant to the memory bus. The IOMMU may also include extra information associated with the address space mapping such as read and write permissions. In a non-virtualized system (i.e., a system without virtual machines), the bus address can be the same as the host physical address.
In a virtual machine system, the guest operating system of a virtual machine usually does not know the host physical address that it accesses; instead, it operates using virtualized guest physical addresses. If the guest operating system tries to instruct a hardware device to perform DMA using the guest physical address, the hardware device would not know the mapping between the virtual and physical addresses used by the system. Thus, the DMA would be performed at the wrong address, which would likely corrupt the memory.
Further, a host system sometimes overcommits its memory to increase the number of virtual machines that it can host. Because it is unlikely that all of the virtual machines will use all of its allocated memory at the same time, the host system may allocate more memory to the virtual machines than what it actually has in the physical memory. As a result, some of the allocated memory may be swapped out to a secondary data storage when it is not in use for a period of time. If a device is allowed to perform DMA to an address not currently resident in the memory, an error will occur. Most devices cannot recover from such errors. Handling the error recovery in real time incurs significant overhead that degrades the performance of the system.